package com.maozzi.common.enums;

import lombok.Getter;

/**
 * 业务码返回信息枚举
 *
 * @author maozi
 */
@Getter
public enum BizCodeEnum implements BizEnum<String> {
    /**
     * 页面错误返回信息
     */
    VIEW_NOT_FOUND("404", "页面走丢了"),
    VIEW_SERVER_ERROR("500", "服务器走神了"),
    /**
     * api 错误码
     */
    OK("200", "成功"),

    NEED_LOGIN("300", "您好，请先登录"),
    LOGINED("301", "账号在另外一台设备登录"),

    WRONG_PARAMETERS("400", "请求参数有误"),
    FILED_AUTH("401", "请求认证失败"),
    FORBIDDEN("403", "没有权限禁止访问"),
    NOT_FOUND("404", "请求资源不存在"),

    SERVER_ERROR("500", "服务器内部错误"),

    CAST_ERROR("600", "类型转换错误"),
    FAILED_OPERATION("601", "操作失败"),
    ;

    private final String code;
    private final String description;

    BizCodeEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String description() {
        return this.description;
    }

    @Override
    public BizEnum<String> value(String code) {
        for (BizCodeEnum i : BizCodeEnum.values()) {
            if (i.code.equals(code)) {
                return i;
            }
        }

        return null;
    }
}
